{"componentChunkName":"component---src-templates-blog-post-js","path":"/How-to-Integrate-dev-to-with-Gatsby/","result":{"data":{"site":{"siteMetadata":{"title":"Aleks Popovic - personal website and blog"}},"markdownRemark":{"id":"a9a4b707-967f-551a-bcee-acb04c3fff4b","excerpt":"My website is built on top of Gatsby, which is a “React-based open source framework with performance, scalability and security built-in”. It’s a fast growing…","html":"<p>My website is built on top of Gatsby, which is a “React-based open source framework with performance, scalability and security built-in”. It’s a fast growing platform with a very active comunity and it has a plethora of plugins which you can use to customize your website. It’s also a static website generator, which introduces certain limitations.</p>\n<p>Static site means no dynamic content. No dynamic content means no comments, likes, bookmarks or similar blog post functionalities that would require a back-end with a database. Not by default at least.</p>\n<p>There are ways to implement all those things on a static website, but I am currently way too lazy to do that. Instead, I went for a partial, but still cool looking solution.</p>\n<p>I cross-post most of my blog posts on dev.to and dev.to blog posts certainly have an implementation for comments and likes (which they call reactions, because there are 3 different kinds). So, I just steal those.</p>\n<span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 1200px; \">\n      <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 51%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAA7CAAAOwgEVKEqAAAACsklEQVQozy2SSU9TURiGG2doQSCA5XYAetsy3XLb25YqUqkIMoYEahFt04oSZZA6oGIAqQoGAtHoAkmUmLgQFTHGCBsTTYgx/gCNf8KFLt09niKLd3G+853nvN+ga20KodXWYyhV2W2tYl9RORlSWhVkiVi2w0NemYZR9iEJGW0auZJCjrWa/cXV5Jld5Ns8FJZ5KXR60RU4NHSSi6P+Zhaiw1y7O0/yzhyDYykizRFS4bMMt56msKsDeTCKYzCBcySBFj1JTU8Ex8UY+cEGMixuMm0CaK2sQWdSmGiLwfJrVr595sGn96xufuTDzDR/Hy7xY/QeFfNDnN98xLP1Jc6/SzG1eJPlpRma12exR7tFRdVkiQp05gq/cKiQFC5+zy7y5elzvr5aY2p0EqfTzYkj7awlrqBMDxJbGSc1G+P6RILY2REmJu/Tv/oYa6RDAFUMsnBYVO5jT7GH0qo6wm2n6GoM09vSg9vfiOSuxx44juprJEerxdHWSVl3hEA4gb81hrclilzXTrZyEH2JhiFdsrHMR6Y4ZIpm57uCFKj1mLwh5EATZndISAzM7iPH5sesBCl21VNZcwybyDGpQQrLD2IQhtIwQ6n2H5ghgFkikOsMkCMkVR3CpNSiFwnpO32pl90lHnYUu9lpVbc+0Nv9ZNhEzywedlndW+/T+bqibWCerHFAdiM7vFgrA9j8IVTtMCaxDkZZJd7RzXz/BZYvDfHsapKFvjjR1nZeDp+jRUx55zZUOPSyVwCNYn0sAnijL8Jksp/gsQhzA+fwe2ux2KvZGLvMr+dP2Hz7hu9rK/xZXuDF9QuwskCqNyycuchOT9kkhqIXZEmAJZvClXic2YEhLDVRtNAZLIEeJKePjat9/Hx4mzvjKeZu3aWhbwalbZj++CjJrk52mFVyRSv+AQeha9km8tDkAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;\"></span>\n  <img class=\"gatsby-resp-image-image\" alt=\"my blog with dev.to icons\" title=\"my blog with dev.to icons\" src=\"/static/5a321ddc424bce7389527fe508e18e8d/64756/blog.png\" srcset=\"/static/5a321ddc424bce7389527fe508e18e8d/a8a0d/blog.png 300w,\n/static/5a321ddc424bce7389527fe508e18e8d/dface/blog.png 600w,\n/static/5a321ddc424bce7389527fe508e18e8d/64756/blog.png 1200w,\n/static/5a321ddc424bce7389527fe508e18e8d/28bdc/blog.png 1800w,\n/static/5a321ddc424bce7389527fe508e18e8d/8e14e/blog.png 1901w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\" loading=\"lazy\">\n    </span>\n<p>When I say “steal”, I actually mean: “There is a Gatsby plugin which allows me to use dev.to API without setting up any API interaction on my end except for passing in my dev.to username”. It is a bit limited, mind you. For example, you can get the number of comments, but not the actual comments. You can get the total number of reactions, but not individual Hearts, Unicorns and Saved/Bookmarked counts.</p>\n<p>Which is fine in my book, for now. It gets the job done and it looks nice. If you have a Gatsby blog and want to do something similar here is how you can do it.</p>\n<p>The plugin in question is <a href=\"https://www.npmjs.com/package/gatsby-source-dev\" target=\"_blank\" rel=\"noopener noreferrer\">gatsby-source-dev</a> which you can install by running one of these commands:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add gatsby-source-dev\nnpm install gatsby-source-dev</code></pre></div>\n<p>We also need to add this in the plugins section of the gatsby-config.js file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  resolve: &quot;gatsby-source-dev&quot;,\n  options: {\n    username: &quot;alekswritescode&quot;,\n  },\n},</code></pre></div>\n<p>Of course, instead of “alekswritescode” you would add your own dev.to username.</p>\n<p>For the next part of the setup I followed an <a href=\"https://dev.to/justinjunodev/add-a-dev-to-blog-feed-to-your-gatsby-site-in-5-mins-168n\" target=\"_blank\" rel=\"noopener noreferrer\">article written by Justin Juno</a>, where he excellently explains how to add an entire dev.to feed to your Gatsby website in just 5 minutes. But, I don’t want an entire feed. I just need the comment and reaction count, and I’m out.</p>\n<p>In his article Justin explains how to add your own custom hook which will pull the data from dev.to API. I modified it a bit, so my hook’s code ended up looking like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// usePosts.js</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> graphql<span class=\"token punctuation\">,</span> useStaticQuery <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"gatsby\"</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">usePosts</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> <span class=\"token function\">useStaticQuery</span><span class=\"token punctuation\">(</span>graphql<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n    query {\n      allDevArticles {\n        edges {\n          node {\n            article {\n              title\n              positive_reactions_count\n              comments_count\n            }\n          }\n        }\n      }\n    }\n  </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span>\n\n  <span class=\"token keyword\">return</span> data<span class=\"token punctuation\">.</span>allDevArticles<span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">post</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    id<span class=\"token operator\">:</span> post<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span>article<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">,</span>\n    title<span class=\"token operator\">:</span> post<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span>article<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">,</span>\n    likes<span class=\"token operator\">:</span> post<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span>article<span class=\"token punctuation\">.</span>positive_reactions_count<span class=\"token punctuation\">,</span>\n    comments<span class=\"token operator\">:</span> post<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span>article<span class=\"token punctuation\">.</span>comments_count<span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> usePosts</code></pre></div>\n<p>Like I said, I only need reactions and comments, and the id is being fetched by default. I am also pulling the post title so I can compare it against my post titles and determine where my “stolen” comments and reactions need to go.</p>\n<p>Now we need to call that hook inside of your blog and/or blog post template. I am not going to post my full code here, since your blog implementation is almost certainly different from mine, but here is the general idea of what you can do.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token comment\">// blog.js</span>\n\n<span class=\"token keyword\">import</span> usePosts <span class=\"token keyword\">from</span> <span class=\"token string\">\"../hooks/usePosts\"</span>\n<span class=\"token keyword\">import</span> Impressions <span class=\"token keyword\">from</span> <span class=\"token string\">\"../components/impressions\"</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Blog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> posts <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">.</span>allMarkdownRemark<span class=\"token punctuation\">.</span>edges\n  <span class=\"token keyword\">const</span> devToPosts <span class=\"token operator\">=</span> <span class=\"token function\">usePosts</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>content<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token punctuation\">{</span>posts<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> node <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> devToArticle <span class=\"token operator\">=</span> devToPosts<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>\n          <span class=\"token parameter\">article</span> <span class=\"token operator\">=></span>\n            article<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> node<span class=\"token punctuation\">.</span>frontmatter<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n\n        <span class=\"token keyword\">let</span> likes <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n        <span class=\"token keyword\">let</span> comments <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>devToArticle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          likes <span class=\"token operator\">=</span> devToArticle<span class=\"token punctuation\">.</span>likes\n          comments <span class=\"token operator\">=</span> devToArticle<span class=\"token punctuation\">.</span>comments\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n          <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>article</span> <span class=\"token attr-name\">key</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>node<span class=\"token punctuation\">.</span>fields<span class=\"token punctuation\">.</span>slug<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            // all of your blog post code goes here\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Impressions</span></span> <span class=\"token attr-name\">likes</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>likes<span class=\"token punctuation\">}</span></span> <span class=\"token attr-name\">comments</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>comments<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>article</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token punctuation\">)</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Blog</code></pre></div>\n<p>So, what’s going on in there? We are importing our hook and a component which will show the number of likes and comments. I will show you how to implement that component as well in a minute. We are then picking up all of our blog post data that’s in my case being sent from the gatsby-node.js. Your implementation may be different, so I won’t go over setting that up in this article.</p>\n<p>We are then mapping our posts into article elements which contain our blog post data. But, before that, we are checking if one of our articles has a title that matches an article from dev.to feed. I name all of my cross-posted articles the same way, so there should always be one match which we can pick up. We pick up likes and comments and pass them into the Impressions component.</p>\n<p>Speaking of the Impressions component, here is what that looks like:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span>\n<span class=\"token keyword\">import</span> impressionsStyles <span class=\"token keyword\">from</span> <span class=\"token string\">\"../styles/impressions.module.css\"</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Impressions</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> likes<span class=\"token punctuation\">,</span> comments <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>impressionsStyles<span class=\"token punctuation\">.</span>impressions<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token punctuation\">{</span>likes <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>impressionsStyles<span class=\"token punctuation\">.</span>impression<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>svg</span>\n            <span class=\"token attr-name\">xmlns</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>http://www.w3.org/2000/svg<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">viewBox</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>0 0 24 24<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">width</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>24<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">height</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>24<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">className</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>impressionsStyles<span class=\"token punctuation\">.</span>impressionIcon<span class=\"token punctuation\">}</span></span>\n          <span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>title</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">DEV.to impressions</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>title</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>path</span> <span class=\"token attr-name\">d</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>M20.243 4.757c2.262 2.268 2.34 5.88.236 8.236l-8.48 8.492-8.478-8.492c-2.104-2.356-2.025-5.974.236-8.236C5.515 3 8.093 2.56 10.261 3.44L6.343 7.358l1.414 1.415L12 4.53l-.013-.014.014.013c2.349-2.109 5.979-2.039 8.242.228z<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>svg</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token punctuation\">{</span>likes<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n      </span><span class=\"token punctuation\">{</span>comments <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>impressionsStyles<span class=\"token punctuation\">.</span>impression<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>svg</span>\n            <span class=\"token attr-name\">xmlns</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>http://www.w3.org/2000/svg<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">viewBox</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>0 0 24 24<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">width</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>24<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">height</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>24<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">className</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>impressionsStyles<span class=\"token punctuation\">.</span>impressionIcon<span class=\"token punctuation\">}</span></span>\n          <span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>title</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">DEV.to comments</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>title</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>path</span> <span class=\"token attr-name\">d</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>M2 12C2 6.477 6.477 2 12 2s10 4.477 10 10-4.477 10-10 10H2l2.929-2.929A9.969 9.969 0 0 1 2 12zm4.828 8H12a8 8 0 1 0-8-8c0 2.152.851 4.165 2.343 5.657l1.414 1.414-.929.929zM8 13h8a4 4 0 1 1-8 0z<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>svg</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token punctuation\">{</span>comments<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In here we are just picking up the number of likes and comments and displaying them alongside an SVG icon if they are greater than zero. The SVG icons are the same ones used on dev.to for comments and “Heart” reactions. If you are wondering where I got those from - you can find these and many more on the <a href=\"https://remixicon.com/\" target=\"_blank\" rel=\"noopener noreferrer\">RemixIcon</a> website. Those are the icons dev.to uses and I wanted to set up the same on my end since I am pulling their data, after all. I wanted a bit of consistency there. Plus, they look super cool, so why not. Don’t sue me, please.</p>\n<p>I added some simple CSS to make everything nice and centered:</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.impressions</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">justify-content</span><span class=\"token punctuation\">:</span> center<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">.impression</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">align-items</span><span class=\"token punctuation\">:</span> center<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">margin-right</span><span class=\"token punctuation\">:</span> 0.5rem<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> 1rem<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">.impressionIcon</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">margin-right</span><span class=\"token punctuation\">:</span> 0.4rem<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">fill</span><span class=\"token punctuation\">:</span> #fd9047<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Of course, you would have your own custom CSS to match this component with the rest of your blog post content and you would position the component acordingly. I placed mine right below the post title and date.</p>\n<p>After that I did the same thing for my template for individual blog posts. The code is pretty much the same, except you you are working with individual blog posts so you don’t need to map through all of them. Just pick up your post’s title, compare it with your dev.to articles and you are set.</p>\n<span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 1200px; \">\n      <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 42%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAA7CAAAOwgEVKEqAAAACEElEQVQoz2WRXUhTYRjHj6RzWH7NaQ6d5+zMs82y5txaNotSS4QZS92GFYSYYV9CKu1CTJnoWTn7IAUDZRlCQRddmVHQpTdd2U1XdSUEQUJ3XnTx6/UMoejix/PyvPx/PO/zSh1tJ6kPNFEk1yO7vVzq6CQejnE7coGRaA+JeIw7PVGG4730R7pp8DczEO5kVNwNhjuo1rxYHEewqkcNJHOFimRxIJWp1ChuNvV7bDx4xI/MAj/XXrG19pqvb9/wOzPH1mKKif6LbE4Pw+pDfs2NUiW7jWxehZPccqdw2V2YDtYiWVVk9RDfZsfYmJnm89I8H1aWWVt6xvrqc7bnJ9nOpLnfF+Pj2HV4ofN9VggddeQIUb5wGJ6Sak3Ys0K7EO4sjMFykvdP0nRPLDIw/pjkVJoVPU37zXmGrvRxvusqswmdnacJqhQhFNn/hDnlKjbZw+bkDb6kRvik3+Vdapz1ZIKXqSlcl3Wks5PU9c5QeuoWkn+QzNA1FNVjDPOPMFe83yTIr9Qocfo54PDh9Ldw7EyYgCB0rotAexRfa4TaUCc2bwsFcgMFSiPmSs3Yn2lPWFylsU/sYLeZJxr7VT8WzwmKXccp1IIUuZqw1TdjOxyi1N2ExRXE6hFVUKD4RCYr3EN8imaYzZVZytxBHP5WFDGhGmgzznJjCzWC3eoQPXvDaUNaqPow2zTMf+X/AGNXIqObqQ6bAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;\"></span>\n  <img class=\"gatsby-resp-image-image\" alt=\"blog post example with dev.to icons\" title=\"blog post example with dev.to icons\" src=\"/static/55ca0f2ff7b97d1054c3c9b9b43097d0/64756/blogPost.png\" srcset=\"/static/55ca0f2ff7b97d1054c3c9b9b43097d0/a8a0d/blogPost.png 300w,\n/static/55ca0f2ff7b97d1054c3c9b9b43097d0/dface/blogPost.png 600w,\n/static/55ca0f2ff7b97d1054c3c9b9b43097d0/64756/blogPost.png 1200w,\n/static/55ca0f2ff7b97d1054c3c9b9b43097d0/28bdc/blogPost.png 1800w,\n/static/55ca0f2ff7b97d1054c3c9b9b43097d0/b381f/blogPost.png 1893w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\" loading=\"lazy\">\n    </span>\n<p>One caveat with this approach is that your blog post data won’t be updated in real time. Since you need to build out your Gatsby website before deploying the static content you will just get a snapshot of that data during the build. This might be important for you, but I don’t mind it that much. I am regularly pushing updates to my website since it’s a constant work in progress. When I push a new build my website catches up to whatever is happening with the dev.to version of the blog post.</p>\n<hr>\n<div class=\"sectionHighlight\">If you have any questions or comments you can reach out to me on <a href=\"https://twitter.com/alekswritescode\" target=\"_blank\" rel=\"noopener noreferrer\">Twitter</a> and <a href=\"https://www.instagram.com/aleks.popovic/\" target=\"_blank\" rel=\"noopener noreferrer\">Instagram</a>, where I also post interesting code tidbits and designs.\n<p>I also have a <a href=\"https://www.youtube.com/AleksPopovic\" target=\"_blank\" rel=\"noopener noreferrer\">YouTube channel</a> where I regularly upload React and web dev tutorials, so if that’s your cup of tea feel free to support me by subscribing.</div></p>","frontmatter":{"title":"How to Integrate dev.to with Gatsby","series":null,"seriesLink":null,"date":"December 27, 2020","description":"My website is built on top of Gatsby, which is a React-based open source framework with performance, scalability and security built-in\". It's a fast growing platform with a very active comunity and it has a plethora of plugins which you can use to customize your website. It's also a static website generator, which introduces certain limitations.","tags":["web","react","gatsby"],"featuredImage":{"childImageSharp":{"fluid":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACF0lEQVQozyWSS28SAQCE+Tse/QFePPkfPBm8aaKJXnswJurNNDFemmpbD5o0Whq0FltapcWGFBD2xe6yy8Iu++ANZaFgKZ+beJjb5MvMZGJLUWcpiFyVS0xEESUtUzwwOfssUdgpU94+pyk3UN0BH1IZ1hM/+H5aYvNjkkLexK9d0K4ETCWdK1EiRrnMPNJQUnGlJlvPM2yupEm8Oubd4yTbb7KcZnQSxyJ343EePnrK6tst4vEH5FJnzKteFEZkEcGGVYvYWJBpyzU8rYWrdikmFWppBfVQILWTR6g2MbsGvxWNZ2tpNhJ/KJ0UON87JixXonYSfyWZgVHHaXaI+YqNp7bxtS7dis+06jBu2JylRF6v7FLUdJxAIVcfcev+GjfuPOHgZxcMi0UEm8kVeqaN7XZRepfEPO0/rFdxGVUsAtXC8nv8OtFZfbFLtijQCaK0BZ+b9z5x++5LDvcN+nmFaQTr1hzqXh9hMEcYLogFWoeRUudCNehYDobdwbxcsvVFIJluRGaXllnEFaq0pIDDowa5/Twj2cAxXGqtIXJ/RiOYMbYmxOZShYmq0667WMEQoT1Bn16zvmFwmm3TafbpyTZhtDOqSO6oxvuvHWzTQ/VG2P6E0AxZ6hMmVlR5rFUJGj5mMELszZC6kZyQ/W8W5UydseYQSgZzQWEZ3aqUrbB30qBcHeDpIddayKI65aIxI3Dn/AMU4SrDrSKMhQAAAABJRU5ErkJggg==","aspectRatio":2.6666666666666665,"src":"/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/0e6e2/integration.png","srcSet":"/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/b460a/integration.png 480w,\n/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/6e898/integration.png 960w,\n/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/0e6e2/integration.png 1920w","srcWebp":"/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/30cf3/integration.webp","srcSetWebp":"/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/35871/integration.webp 480w,\n/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/fcc10/integration.webp 960w,\n/static/60cbc3a5ad8f91e8d2b3ad5b9195b087/30cf3/integration.webp 1920w","sizes":"(max-width: 1920px) 100vw, 1920px"}}}}}},"pageContext":{"slug":"/How-to-Integrate-dev-to-with-Gatsby/","previous":{"excerpt":"Until a few days ago I had no idea voice control and speech recognition were such a big deal. I lost the link to it, but according to an…","fields":{"slug":"/Build-Voice-Navigation-with-React-and-Speech-Recognition/"},"frontmatter":{"date":"December 19, 2020","title":"Build Voice Navigation with React and Speech Recognition","series":null,"description":"Until a few days ago I had no idea voice control and speech recognition were such a big deal. I lost the link to it, but according to an article I read, a big percentage of population likes to talk into their phones and home assistants. Maybe I am getting old, since it looked like the age group that uses it the most is 16-24? I think that's great (using the tech, not me getting old). Not only does it promote even more accessibility on the web, but it also gives us a glimpse into a future where we are no longer slaves to our clumsy fingers. I personally make too many typing mistakes, both on PC and smartphone keyboards.","tags":["web","react"],"featuredImage":{"id":"85d90288-b834-5a78-89b5-92e68eb93caa","publicURL":"/static/a2244cabb7554fc37a4a2a8d6be10da4/voice.png","relativeDirectory":"Build-Voice-Navigation-with-React-and-Speech-Recognition","relativePath":"Build-Voice-Navigation-with-React-and-Speech-Recognition/voice.png"}}},"next":{"excerpt":"Building projects is one of the best ways to learn a new technology or to get better with a stack you are already familiar with. Wanting to…","fields":{"slug":"/How-to-choose-your-next-side-project/"},"frontmatter":{"date":"January 03, 2021","title":"How to choose your next side project","series":null,"description":"This approach will teach you how to figure out project ideas on your own. The ideas will be yours, you will be passionate about finishing your projects based on them, and you will build out your portfolio with projects that actually mean something to you.","tags":["productivity"],"featuredImage":{"id":"9cf458f0-5f80-5a7d-9ad8-b8baf89a9133","publicURL":"/static/900144a81ada78f750bf453d764360d1/index.png","relativeDirectory":"How-to-choose-your-next-side-project","relativePath":"How-to-choose-your-next-side-project/index.png"}}}}}}